<%@page import="com.beans.CategoryForm"%>
<%@page import="com.DAO.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="getData" uri="/WEB-INF/CustomTagDescriptor.tld" %> 

 <%!int i=0;String categoryId=null;
            String str=null;
            int totalpages=0;
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel = "stylesheet" href = "style/Global.css" />

<style>

			

</style>

</head>

<%
      categoryId=session.getAttribute("id").toString();
      
	  NoticeDAO noticeDAO=new NoticeDAO();
	  
	  try{
			int noticecount=noticeDAO.getNoticeCountByCategory(Integer.parseInt(categoryId));
			  
            if(noticecount%5==0){
  					totalpages=noticecount/5;
            }
            else
            {
            	    totalpages=(noticecount/5)+1;
            }
		  
	 
	  System.out.println("Total pages are...."+totalpages);
	  
	  }
	  catch(Exception e){
		  System.out.println("Error in count notices....");
	  }
	  
	 


	  if(request.getParameter("pageno")!=null){
	  		i=Integer.parseInt(request.getParameter("pageno"));
	  }	  
	  	  
	  else {		  
String op=request.getParameter("op");
System.out.print("op is..........."+op);

if(op!=null)
{    
    if(op.equals("next"))
    {
    	   
    	   String counter=request.getParameter("counter");
    	   if(counter==null)
    	   {
    		   i=0;    		   
    	   }
    	   else
    	   {
    		   
    		    i=Integer.parseInt(counter)+1;
    	   }
    }   
    else
    {
    	String counter=request.getParameter("counter");
    	if(counter==null){
 		   i=0;    		   
 	   }
 	   else if(Integer.parseInt(counter)>0){
 		     i=Integer.parseInt(counter)-1;
 	   }
    	
    }
}   
else{
	i=0;
}


	  } //else

%>



	<%	str=i+"";
		System.out.println("Cursor value is........."+Integer.parseInt(str));
	%>
	<div class = "categorytitle">
	        
	        <% 
	           CategoryDAO catDAO=new CategoryDAO();
	           CategoryForm catForm=catDAO.getCategoryInfo(Integer.parseInt(categoryId));
	         %>
	         <%=catForm.getName()%>
	        
	                   
	</div>
	<getData:notice1 cursor="<%=str%>" category="<%=categoryId%>"/>
	
	

	<div id = "pager">	 
	<%if(Integer.parseInt(str)>0)
	{%>
	<a id = "btnprev" href="viewCategory-1.jsp?counter=<%=str%>&op=pre"> <img src = "image/46.jpg" alt = "Previous"></a>
	<%} %>
	
	<div id = "pageno">
	<%if(totalpages != 0) { %>
	<%=i+1%> of <%=totalpages%>
	<%} %>
	</div>
	
	<%if(Integer.parseInt(str)<totalpages-1){ %>
	<a id = "btnnext" href="viewCategory-1.jsp?counter=<%=str%>&op=next"><img src = "image/43.jpg" alt = "Next"></a>
	<%} %>	 
	</div>
<body>




	



</body>
</html>